<?php 

/**
 *  @author 
 *  Lindon Camaj 
 *  
 *  @file
 *  My upload settings
 */

function my_upload_admin_settings($form, &$form_submit){
    
    $my_files = variable_get('upload_files', array());
    
    $form['image_name'] = array(
        '#title' => t('Image name (title)'),
        '#type' => 'textfield',
        '#maxlength' => 30,
        '#size' => 30,
        '#required' => true,        
    );
    
    $form['m_file_path'] = array(
        '#type' => 'textfield',
        '#title' => t('Image path (url)'),
        '#maxlength' => 300,
        '#size' => 50,
        '#required' => true,
    );
    
    $form['show_main_page'] = array(
        '#type' => 'checkbox',
        '#title' => 'Show image in main page',
        '#return_value' => 1,
        '#default_value' => 0,
    );
    
    $form['my_files'] = array(
        '#title' => 'Images list',
        '#type' => 'fieldset',
        '#collapsible' => true,
        '#collapsed' => false,
    );
    
    /*
     * If my_files is not empty show the data as html
     */
    $html_text = '<div>';
    if(count($my_files) > 0){
        foreach($my_files as $row){
            $html_text .= "<div style='float:left;'>";
            $html_text .= "<div style='text-align:center'><span>" . $row['name'] . "</span></div>";
            $html_text .= "<div><img height='64px' src='" . $row['image'] . "'/></div>";
            $html_text .= "</div>";
        }
        $html_text .= "<div style='clear: both;'></div></div>";
    }
    else{
        $html_text = "nothing to show....";
    }
    
    $form['my_files']['html_show'] = array(
            '#type' => 'markup',
            '#markup' => $html_text,
    );
    
    $form['submit'] = array(
            '#type' => 'submit',
            '#value' => 'Submit',
    );
    
    //return system_settings_form($form); // Retutrn form
    return $form;
}

/*
 *  Submit File
 */
function my_upload_admin_settings_submit($form, &$form_submit){
    
    if(user_access('administer my_upload')){
        $my_upload = variable_get('upload_files', array());
        
        $my_upload[] = array(
            'name' => $form_submit['values']['image_name'],
            'image' => $form_submit['values']['m_file_path'],
            'main_visible' => $form_submit['values']['show_main_page'],
        );
        
        variable_set('upload_files', $my_upload);
        
        drupal_set_message(t("Successsfuly added image"));
    }
    else{
        drupal_set_message(t("Error:"));
    }
    
}


